﻿@using HuntingFishGame.ManageDomain.Model.WeChat;
@model AutoReplyModel
@{
    ViewBag.Title = "AddOrEdit";
    Layout = "~/Views/Shared/_Layout.cshtml";
    Dictionary<string, string> stateDic = ViewBag.StateList as Dictionary<string, string>;
}
<style>

</style>

<script>
    function sub() {
        return checkForm();
    }
    //return save()
    function save() {
        var result = checkForm();
        if (!result) {
            return false;
        }
        return true;
    }
    function checkForm() {
        var $keyword = $("#keyword");
        var $content = $("#content");
        if ($.trim($keyword.val()).length <= 0) {
            alert("请填写关键词！");
            $keyword.focus();
            return false;
        }
        if ($.trim($content.val()).length <= 0) {
            alert("请输入自动回复内容！");
            $content.focus();
            return false;
        }
        if ($("#remark").val().length < 5) {
            alert("备注不得少于5个字符");
            return false;
        }
        if ($("#sfdj").val() == "") {
            alert("请选择是否冻结！");
            return false;
        }
        return true;
    }
    //登录提交
    function Submit() {
        var ret = checkForm();
        if (!ret) {
            return;
        }
        //验证通过，提交登录
        $.ajax({
            url: "/AutoReply/AddOrEdit?@Html.Raw(Request.QueryString.ToString())",
            data: {
                'id': $("#id").val().trim(),
                'keyword': $("#keyword").val().trim(),
                'content': $("#content").val().trim(),
                "remark": $("#remark").val(),
                "sfdj": $("#sfdj").val()
            },
            type: "POST",
            success: function (data) {
                //提交成功直接转入地址
                if (data.code === 1) {
                    if (data.ReturnUrl === "" || data.ReturnUrl == null) {
                        window.location.href = "@SiteUrls.Instance().Success()";
                    } else {
                        window.location.href = decodeURIComponent(data.ReturnUrl);
                    }
                } else {
                    alert(data.msg);
                }
            },
            error: function () {
                alert("系统发生未知错误");
            }
        });
    }
    //$(document).ready(function () {
    //    $('form').bind('submit', checkform);
    //});
    //function checkform() {
    //    alert("提交前的验证");
    //    return false;
    //}
</script>
<div class="head">
    <div class="title">
        新增自动回复消息
    </div>
</div>
<div>
    @*@using (Html.BeginForm("AddOrEdit", "AutoReply", FormMethod.Post, new { enctype = "multipart/form-data", @onsubmit = "return sub()", @class="" })){ }*@
    <input type="hidden" id="id" name="id" value="@Model.id" />
    <ul class="mydetail">
        <li>
            <label>关键词</label><input class="mylongtext" type="text" id="keyword" name="keyword" value="@Model.keyword" />
        </li>
        <li>
            <label>自动回复内容</label><input class="mylongtext" type="text" id="content" name="content" value="@Model.content" />
        </li>
        <li>
            <label>备注</label><textarea id="remark" name="remark" style="height: 200px">@Model.remark</textarea>
        </li>
        <li>
            <label>是否冻结</label><select id="sfdj" name="sfdj">
                <option value="0">请选择</option>
                @{
                    foreach (KeyValuePair<string, string> k in stateDic)
                    {
                        <option value="@k.Key" @Html.Raw(k.Key == Model.sfdj.ToString().ToLower() ? "selected=selected" : "")>@k.Value</option>
                    }
                }
            </select><span class="red">否->启用，是->禁用</span>
        </li>
        <li>
            <input type="submit" class="btn1" value="提交" onclick="Submit()" />
        </li>
    </ul>
</div>

